<template>
   <div class="passwd">
        <div class="change-passwd">
            <div class="setting-options">
                <mt-field label="当前密码" placeholder="请输入当前密码" type="password" v-model="oldPasswd" class="person-cell "></mt-field>
                <mt-field label="新密码" placeholder="请输入新密码" type="password" v-model="newPasswd" class="person-cell"></mt-field>
                <mt-field label="确认新密码" placeholder="请确认新密码" type="password" v-model="confirmPasswd" class="person-cell"></mt-field>
            </div>
        </div>
        <div class="confirm" @click="confirm">确认修改</div>
    </div>
</template>
<script>
import { post } from '../../../../util/http.js'
import { Toast } from 'mint-ui'
export default {
    data() {
        return {
            oldPasswd: '',
            newPasswd: '',
            confirmPasswd: ''
        }
    },
    methods: {
        confirm() {
            let info = JSON.parse(window.localStorage.getItem('dongHang_data'))
            if (!this.oldPasswd) {
                Toast({
                    message: '请输入旧密码',
                    duration: 1000
                })
                return
            }
            if (!this.newPasswd) {
                Toast({
                    message: '请输入新密码',
                    duration: 1000
                })
                return
            }
            if (!this.confirmPasswd) {
                Toast({
                    message: '请再次输入新密码',
                    duration: 1000
                })
                return
            }
            if(this.newPasswd == this.confirmPasswd) {
                 post('http://dlsapi.rz158.com/agent/updatePassword', {
                    agentId: info.agentId,
                    password: this.oldPasswd,
                    newPassword: this.newPasswd
                }).then(res => {
                    Toast({
                        message: res.message,
                        duration: 1000
                    })
                    if(res.code == 0) {
                         this.$router.push('/my_setting')   //操作成功
                    }
                })
            } else {
                Toast({
                    message: '输入的两次新密码不相同',
                    duration: 1000
                })
            }
        }
    }
}
</script>
<style lang="less" scoped>
.change-passwd{
    background: #efefef;
     .setting-options {
        margin-top: 4px;
        padding-left: .3rem;
        margin-bottom: .2rem;
        background: #fff;
        .person-cell {
             border-bottom: 1px solid #cccccc;
        }
    }
}
.confirm{
    margin: .8rem auto;
    width: 3.06rem;
    height: .88rem;
    background: #29abae;
    color: #fff;
    font-size: .32rem;
    border-radius: 5px;
    text-align: center;
    line-height: .88rem;
}
</style>


